import { defineStore } from 'pinia';
import { ref } from 'vue';

interface Api {
  id: string;
  name: string;
  url: string;
  method: string;
  status: 'active' | 'inactive';
}

export const useApiStore = defineStore('api', () => {
  const apis = ref<Api[]>([]);

  const fetchApis = async () => {
    // TODO: 实现从后端获取API列表
    return apis.value;
  };

  const createApi = async (api: Omit<Api, 'id'>) => {
    // TODO: 实现创建API
    const newApi = {
      ...api,
      id: Date.now().toString()
    };
    apis.value.push(newApi);
    return newApi;
  };

  const updateApi = async (api: Api) => {
    // TODO: 实现更新API
    const index = apis.value.findIndex(a => a.id === api.id);
    if (index !== -1) {
      apis.value[index] = api;
    }
    return api;
  };

  const deleteApi = async (id: string) => {
    // TODO: 实现删除API
    apis.value = apis.value.filter(api => api.id !== id);
  };

  return {
    apis,
    fetchApis,
    createApi,
    updateApi,
    deleteApi
  };
}); 